<!DOCTYPE html>
<html>
<head>
	<title>dhtmlxscheduler</title>
	<meta name="keywords" content="keyword1,keyword2,keyword3">
	<meta name="description" content="this is my page">
	<meta name="content-type" content="text/html; charset=UTF-8">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" href="../../../dhtmlxscheduler/dhtmlxscheduler.css">
	<style type="text/css" media="screen">
		html, body{
			margin:0px;
			padding:0px;
			height:100%;
			overflow:hidden;
		}
	</style>
</head>
<body>
<div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:64%;'>
	<div class="dhx_cal_navline">
		<div class="dhx_cal_prev_button"> </div>
		<div class="dhx_cal_next_button"> </div>
		<div class="dhx_cal_today_button"></div>
		<div class="dhx_cal_date"></div>
		<div class="dhx_minical_icon" id="dhx_minical_icon"> </div>
		<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
		<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
		<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
	</div>
	<div class="dhx_cal_header">
	</div>
	<div class="dhx_cal_data">
	</div>
</div>
<script src="../../../bpmn/jquery.js"></script>
<script src="../../../dhtmlxscheduler/dhtmlxscheduler.js"></script>
<script src="../../../dhtmlxscheduler/locale_cn.js"></script>
<script type="text/javascript" charset="utf-8">
	$(function() {
		init();
		$("#dhx_minical_icon").click(show_minical);

		//初始化并且获取已经添加的日程
		function init() {
			scheduler.config.multi_day = true;
			scheduler.config.drag_move = false;
			scheduler.config.icons_edit = ['icon_custom', 'icon_save', 'icon_cancel'];
			scheduler.config.icons_select = ['icon_details', 'icon_delete'];
			scheduler.config.xml_date="%Y-%m-%d %H:%i";
			scheduler.init('scheduler_here',new Date(),"month");
			/*$.ajax({
				url: '${ctx}/getPage/1',
				cache:false,
				success:function(data) {
					var events = [];
					var info = eval(data);
					for (var i = 0; i < info.length; i++) {
						var ev = info[i];
						var title = ev.event;
						var start = ev.startDate;
						var end = ev.endDate;
						var event_id = ev.eventId;
						var id=ev.id;
						//组装日程
						events.push({
							id:id,
							event_id:event_id,
							text:title,
							start_date:start,
							end_date:end
						});

					}
					scheduler.parse(events, "json");
				},
				error:function() {
					alert('数据错误！');
				}
			});*/

			/**
			 *添加保存事件数据操作
			 */
			scheduler.attachEvent("onEventAdded",function(event_id,ev,is_new){
				if (!ev.text) {
					alert("描述信息不能为空！");
					return false;
				}
				if(ev.start_date>ev.end_date){
					alert("开始时间不能在结束时间之后");
					return false;
				}
				var parms = {eventId:event_id,event:ev.text,startDate:ev.start_date,endDate:ev.end_date};
				$.ajax({
					url:"${ctx}/addCalendar",
					dataType:'json',
					type:"post",
					data:{"calendarInfo":JSON.stringify(parms)},
					success:function(data){

					},
					error:function(){

					}
				});
				return true;
			});
			/**
			 *添加删除事件数据操作
			 */
			scheduler.attachEvent("onBeforeEventDelete", function(event_id,ev){
				$.ajax({
					url:"${ctx}/delCalendar",
					dataType:'json',
					type:"post",
					data:{"event_id":event_id},
					success:function(data){

					},
					error:function(){

					}
				});
				return true;
			});
			/**
			 *添加编辑事件数据操作
			 */
			scheduler.attachEvent("onEventChanged", function(event_id,ev){
				if (!ev.text) {
					alert("描述信息不能为空！");
					return false;
				}
				if(ev.start_date>ev.end_date){
					alert("开始时间不能在结束时间之后");
					return false;
				}
				var parms = {eventId:ev.event_id,event:ev.text,startDate:ev.start_date,endDate:ev.end_date};
				$.ajax({
					url:"${ctx}/addCalendar",
					dataType:'json',
					type:"post",
					data:{"calendarInfo":JSON.stringify(parms)},
					success:function(data){

					},
					error:function(){

					}
				});
				return true;
			});
		}
		//显示迷你日历表
		function show_minical(){
			if (scheduler.isCalendarVisible())
				scheduler.destroyCalendar();
			else
				scheduler.renderCalendar({
					position:"dhx_minical_icon",
					date:scheduler._date,
					navigation:true,
					handler:function(date,calendar){
						scheduler.setCurrentView(date);
						scheduler.destroyCalendar()
					}
				});
		}
	});

</script>
</body>
</html>
